<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;

use OT\DataDictionary;


/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController
{

    //系统首页
    public function index()
    {

        echo 'shouye';
    }

    /**
     * 花呗支付 同步跳转方法
     * 调用分账方法
     */
    public function huabeiReturnUrl()
    {
        $url = "http://hbxyk.hihaoge.me/admin/test/test";
        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);

        //执行并获取HTML文档内容
        $output = curl_exec($ch);
        //释放curl句柄
        curl_close($ch);
    }

    /**
     * 支付宝授权列表页
     */
    public function authorization(){
        $uid = I('uid');
        $kbsh_id = I('kbsh_id'); //码商id
        $list = M('shouquan')->select();
        foreach($list as $k => $v){
            $list[$k]['url'] =  "https://openauth.alipay.com/oauth2/appToAppAuth.htm?app_id=" . $v['appid'] . "&redirect_uri=http://hbxyk.hihaoge.me/pay.php&uid=$uid&kbsh_id=$kbsh_id";
        }

        $this->assign('list',$list);
        $this->display();
    }

    public function base64ImageSave(){
        base64ImageSave($img);
    }



    /***
     * ceshi
     */
    public function test(){
//        $adata = M('kbsh')->where(['uid' => 1063,'status' => 1, 'use_status' => 1])->find();//商户信息
        $adata = M('alipays')->where(['pid' => 2088331374431371])->find();
        dump($adata);
    }

    public function test1(){

        $redis = new \Predis\Client(C('REDIS'),['prefix' => C('REDIS_PREFIX')]);
//        $redis->del('list1');
//        $redis->del('list2');
//        $redis->rpush('list1','a1');
//        $redis->rpush('list1','b1');
//        $redis->rpush('list1','c1');
//        $redis->rpush('list1','d1');
//        $redis->rpush('list1','e1');

//        if($redis->llen('list1') > 0 && $redis->llen('list2') == 0){
//            $redis->rpoplpush('list1','list2');
//
//        }else{
//            $redis->rpoplpush('list2','list1');
//
//        }
        $redis->rpoplpush('list1','list1');
        $list1 = $redis->lrange('list1',0,-1);
//        $list2 = $redis->lrange('list2',0,-1);
//        dump(['list1' => $list1, 'list2' => $list2]);
        echo $redis->lindex('list1',0);

        dump(['list1' => $list1]);
    }

    public function test2(){
        $num = 123213.666666;
        echo sprintf("%.2f",substr(sprintf("%.3f", $num), 0, -2));
    }

    public function test3(){

        $time1 = strtotime(date("Ymd"));
        $time2 = strtotime(date("Ymd")) + 86400;
        $m = M('Split')->where([ 'status' => 1,'seller_id' => '2088231208650812'])->where("`time` between '$time1' and '$time2'")->sum('sh_money'); //口碑收益获得
        echo $m;
        echo M('Split')->getLastSql();
    }


}